import 'package:flutter/cupertino.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/routes/call/controller/xindong_call_controller.dart';
import 'package:xindong/routes/conversation/model/xindong_liaotian_detail_class.dart';
import 'package:xindong/widgets/dialog/xindong_base_sheet.dart';

class XinDongCallOptionSheet extends XinDongBaseSheet {
  final XinDongLiaoTianDetailClass model;
  final Function(int callType) onSelect;

  XinDongCallOptionSheet.show({super.key, required this.model, required this.onSelect}) {
    showSheetDialog(sheet: this);
  }

  @override
  Widget build(BuildContext context) {
    final dataList = [];
    if (model.another.isFemale) {
      if (model.another.video_switch == 1) {
        dataList.add({
          "name": "视频通话",
          "price": "${model.another.video_price}",
          "type": XinDongCallType.videoCall,
        });
      }
      if (model.another.voice_switch == 1) {
        dataList.add({
          "name": "语音通话",
          "price": "${model.another.voice_price}",
          "type": XinDongCallType.audioCall,
        });
      }
    } else {
      final user = XinDongUserController.to.userInfo!;
      if (user.configPersonal?.video_switch == 1) {
        dataList.add({
          "name": "视频通话",
          "price": user.configPersonal?.video_price ?? "0",
          "type": XinDongCallType.videoCall,
        });
      }
      if (user.configPersonal?.voice_switch == 1) {
        dataList.add({
          "name": "语音通话",
          "price": user.configPersonal?.voice_price ?? "0",
          "type": XinDongCallType.audioCall,
        });
      }
    }

    return XinDongBaseSheet(
      body: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          MediaQuery.removePadding(
            removeTop: true,
            removeBottom: true,
            context: context,
            child: ListView.separated(
              shrinkWrap: true,
              physics: const NeverScrollableScrollPhysics(),
              itemCount: dataList.length,
              itemBuilder: (BuildContext context, int index) {
                Map item = dataList[index];
                return buildContainerOption(item["name"], item["price"], () {
                  Navigator.pop(context, index);
                  onSelect(item["type"]);
                });
              },
              separatorBuilder: (BuildContext context, int index) {
                return Container(height: 1.0, color: DZColors.dividerColor);
              },
            ),
          ),
          Container(height: 1.0, color: DZColors.dividerColor),
          GestureDetector(
            onTap: () => Navigator.pop(context),
            behavior: HitTestBehavior.opaque,
            child: Container(
              height: 50,
              alignment: Alignment.center,
              child: const Text(
                "取消",
                style: TextStyle(color: DZColors.mainColor),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget buildContainerOption(String name, String price, Function() onTap) {
    const titleTextStyle =
        TextStyle(color: DZColors.titleColor, fontSize: 16.0, fontWeight: FontWeight.normal, height: 1.2);
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.opaque,
      child: SizedBox(
        height: 56,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(name, style: titleTextStyle),
            Text(
              "$price金币/1分钟",
              style: const TextStyle(fontSize: 12, fontWeight: FontWeight.normal, color: DZColors.placeholderColor),
            )
          ],
        ),
      ),
    );
  }
}
